package com.nghia.controller;

import java.io.IOException;

import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class Login {
	private String username;
	private String password;
	
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String doLogin(){
		ExternalContext externalContext=FacesContext.getCurrentInstance().getExternalContext();
		RequestDispatcher requestDispatcher=((ServletRequest)externalContext.getRequest()).getRequestDispatcher("/j_spring_security_check?j_username="+username+"&j_password="+password);
		try {
			requestDispatcher.forward((ServletRequest) externalContext.getRequest(),(ServletResponse)externalContext.getResponse());
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		FacesContext.getCurrentInstance().responseComplete();
		return null;
	}
	
}
